package com.situ.study.day7.homework;

import org.junit.Test;

import java.util.Scanner;

public class Demo {

    @Test
    public void test1() {
        Number number = new Number(3, 5);
        int result = number.add();
        System.out.println(result);
        number.sub();
    }

    @Test
    public void test2() {
        Rect rect = new Rect(3, 4);
        int zhouChang = rect.zhouChang();
    }

    //1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
    @Test
    public void test4() {
        int num = 0;
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        for (int i = 0; i <= 9; i++) {
            int count = 0;
            for (int j = 0; j < scores.length; j++) {
                System.out.println(++num);
                if (i == scores[j]) {
                    count++;
                }
            }
            System.out.println(i + "出现的次数： " + count);
        }
    }

    @Test
    public void test5() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int count0 = 0;
        int count1 = 0;
        int count2 = 0;
        int count9 = 0;
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    count0++;
                    break;
                case 1:
                    count1++;
                    break;
                case 9:
                    count9++;
                    break;
            }
        }
        System.out.println("0出现次数： " + count0);
        System.out.println("1出现次数： " + count1);

    }

    @Test
    public void test6() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int[] counts = new int[10];
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    counts[0]++;
                    break;
                case 1:
                    counts[1]++;
                    break;
                case 9:
                    counts[9]++;
                    break;
            }
        }
        for (int i = 0; i < counts.length; i++) {
            System.out.println(i + "出现的次数：" + counts[i]);
        }

    }

//    2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//    要求求出其中的奇数个数和偶数个数。
    @Test
    public void test44() {
        int[] scores = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int evenCount = 0;
        int oddCount = 0;
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] % 2 == 0) {
                evenCount++;
            } else {
                oddCount++;
            }
        }
        System.out.println("奇数： " + oddCount);
        System.out.println("偶数： " + evenCount);
    }

    //题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同
    @Test
    public void test55() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = scanner.next();// "abca"
        char[] array = str.toCharArray();
        //初始认为是回文
        boolean isHuiWen = true;
        for (int i = 0; i < array.length / 2; i++) {
            if (array[i] != array[array.length - i -1]) {
                isHuiWen = false;
                break;
            }
        }

        if (isHuiWen) {
            System.out.println(str + "是回文");
        } else {
            System.out.println(str + "不是回文");
        }
    }

    //输入一行字符串，分别统计出其中英文字母、空格、数字和其它字符的个数。
    @Test
    public void test77() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = scanner.nextLine();
        char[] array = str.toCharArray();
        int digitalCount = 0;
        int characterCount = 0;
        int blankCount = 0;
        int otherCount = 0;
        for (int i = 0; i < array.length; i++) {
            char ch = array[i];
            if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
                characterCount++;
            } else if (ch >= '0' && ch <= '9') {
                digitalCount++;
            } else if (ch == ' ') {
                blankCount++;
            } else {
                otherCount++;
            }
        }

        System.out.println("数字出现次数： " + digitalCount);
        System.out.println("字符出现次数： " + characterCount);
        System.out.println("空格出现次数： " + blankCount);
        System.out.println("其他出现次数： " + otherCount);


    }

}
